//
//  BuyPigCell.m
//  PigMarket
//
//  Created by mac on 2019/4/10.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "BuyPigCell.h"
#import "PigTrusteePriceView.h"
#import "AdoptedTrusteeView.h"

@interface BuyPigCell ()
/**
 title
 */
@property (nonatomic , strong) UILabel *title;
/**
 可多选
 */
@property (nonatomic , strong) UILabel *moreSelectLab;
/**
 rightDetailLab
 */
@property (nonatomic , strong) UILabel *rightDetailLab;
/**
 icon
 */
@property (nonatomic , strong) UIImageView *icon;
@end
@implementation BuyPigCell

#pragma mark - init method
+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *identifierID = @"identifierID";
    BuyPigCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierID];
    if (cell == nil) {
        cell = [[BuyPigCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifierID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self.contentView addSubview:self.icon];
    [self.contentView addSubview:self.title];
    [self.contentView addSubview:self.moreSelectLab];
    [self.contentView addSubview:self.rightDetailLab];
}

- (void)initLayout {
   
    // 布局子控件
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
    }];
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).offset(6);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(20);
    }];
    [self.moreSelectLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.title.mas_right).offset(5);
        make.centerY.mas_equalTo(self.title.mas_centerY);
    }];
    [self.rightDetailLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.centerY.mas_equalTo(self.title.mas_centerY);
        make.height.mas_equalTo(20);
    }];
}
- (void)configCellWithLeftTitleDic:(NSDictionary *)leftTitleDic indexPath:(NSIndexPath *)indexPath {

    self.title.text = leftTitleDic[@"title"];
    self.moreSelectLab.text = leftTitleDic[@"tips"];
    self.rightDetailLab.text = leftTitleDic[@"detail"];
    
    if ([leftTitleDic[@"icon"] length] > 0) {
        self.icon.image = [UIImage imageNamed:leftTitleDic[@"icon"]];
        if ([leftTitleDic[@"detail"] rangeOfString:@"可用豚券"].location != NSNotFound) {
            self.rightDetailLab.textColor = [UIColor tipsGrayColor];
        } else {
            self.rightDetailLab.textColor = [UIColor colorWithHexString:@"F25C62"];
        }
    }else {
        self.rightDetailLab.textColor = [UIColor colorWithHexString:@"#999999"];
        self.icon.hidden = YES;
        [self.title mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.centerY.mas_equalTo(self.contentView.mas_centerY);
            make.height.mas_equalTo(20);
        }];
    }
    if ([leftTitleDic[@"title"] isEqualToString:@"结算信息"]) {
        self.rightDetailLab.hidden = YES;
    }else {
        self.rightDetailLab.hidden = NO;
    }
}
#pragma mark - getter and setter

- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.textColor = [UIColor textBlackColor];
        _title.font = [UIFont largerFont];
        _title.text = @"托管阶段";
    }
    return _title;
}
- (UILabel *)moreSelectLab {
    if (!_moreSelectLab) {
        _moreSelectLab = [[UILabel alloc] init];
        _moreSelectLab = [[UILabel alloc] init];
        _moreSelectLab.textColor = [UIColor colorWithHexString:@"#999999"];
        _moreSelectLab.font = [UIFont systemFontOfSize:13];
        _moreSelectLab.text = @"可多选";
    }
    return _moreSelectLab;
}
- (UILabel *)rightDetailLab {
    if (!_rightDetailLab) {
        _rightDetailLab = [[UILabel alloc] init];
        _rightDetailLab = [[UILabel alloc] init];
        _rightDetailLab.font = [UIFont systemFontOfSize:13];
        _rightDetailLab.textAlignment = NSTextAlignmentRight;
    }
    return _rightDetailLab;
}
- (UIImageView *)icon {
    if (!_icon) {
        _icon = [[UIImageView alloc] init];
        
    }
    return _icon;
}
@end


#pragma mark ------------------ 套餐cell--------------------
@interface TrusteeCell ()
/**
 未领养
 */
@property (nonatomic , strong) PigTrusteePriceView *unadoptTrusteeView;
/**
 已领养
 */
@property (nonatomic , strong) AdoptedTrusteeView *adoptedTrusteeView;
@end
@implementation TrusteeCell

+ (instancetype)cellWithTrusteeTableView:(UITableView *)tableView {
    static NSString *identifierID = @"identifierID";
    TrusteeCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierID];
    if (cell == nil) {
        cell = [[TrusteeCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifierID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}
#pragma mark - init method
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
        [self initLayout];
        [self initAction];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self.contentView addSubview:self.unadoptTrusteeView];
    [self.contentView addSubview:self.adoptedTrusteeView];
}
- (void)initAction {
  
}

- (void)initLayout {
    // 布局子控件
    [self.unadoptTrusteeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(0);
    }];
    [self.adoptedTrusteeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(0);
    }];
}

/**
 赋值

 @param dataArr 数据数组
 @param trusteeType 区分是未领养  和  已领养  对应的套餐页面
 */
- (void)configCellWithDataArr:(NSMutableArray *)dataArr type:(TrusteeType)trusteeType {
    switch (trusteeType) {
        case TrusteeTypeUnAdopted:
            self.unadoptTrusteeView.dataArr = dataArr;
            self.adoptedTrusteeView.hidden = YES;
            break;
        case TrusteeTypeAdopted:
            self.adoptedTrusteeView.dataArr = dataArr;
            self.unadoptTrusteeView.hidden = YES;
            break;
        default:
            break;
    }
}

#pragma mark - getter and setter
- (PigTrusteePriceView *)unadoptTrusteeView {
    if (!_unadoptTrusteeView) {
        _unadoptTrusteeView = [[PigTrusteePriceView alloc] init];
    }
    return _unadoptTrusteeView;
}
- (AdoptedTrusteeView *)adoptedTrusteeView {
    if (!_adoptedTrusteeView) {
        _adoptedTrusteeView = [[AdoptedTrusteeView alloc] init];
    }
    return _adoptedTrusteeView;
}
@end
